package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 发票抬头类型枚举
 * @author zcp
 * @version v1.0
 * @date 2019/7/4 14:01
 * @since v1.0
 */
@Getter
public enum InvoiceTitleTypeEnum {
    //发票抬头类型
    CORP("1", "enum.invoiceTitleType.name.corp"),
    PERSON("2", "enum.invoiceTitleType.name.person"),
    ;
    /**
     * code
     */
    private String value;
    /**
     * 中文名
     */
    private String name;

    InvoiceTitleTypeEnum(String value, String name){
        this.value = value;
        this.name = name;
    }

    /**
     * 通过value获取抬头类型名称
     * @param value
     * @return java.lang.String
     * @author zcp
     * @date 2019/7/4 14:07
     * @since v1.0
     * @version v1.0
     */
    public static String getNameByValue(String value){
        for (InvoiceTitleTypeEnum cache : values()) {
            if (Objects.equals(value, cache.value)) {
                return cache.getName();
            }
        }
        return CORP.getName();
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
